{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import requests\n",
    "api_secret ='N7rXgft8DfOfDM_E0_vXkkJfnqo8mmxs'\n",
    "api_key ='1yIL3rfLicVRlj6rVnGfzbnuq3-zD_FU'\n",
    "BASE_URL = 'https://api-cn.faceplusplus.com/facepp/v3/detect' \n",
    "img_url ='https://gitee.com/huang_jun_hao/wx923/raw/master/chengguo.jpg'\n",
    "headers = {\n",
    "    'Content-Type': 'application/json',\n",
    "}\n",
    "payload = {\n",
    "    \"image_url\":img_url,\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'return_attributes':'gender,age,smiling,emotion', \n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r = requests.post(BASE_URL, params=payload, headers=headers)\n",
    "r.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'{\"request_id\":\"1603532271,6e3be2f7-782c-4902-9e36-246fe16ab589\",\"time_used\":736,\"faces\":[{\"face_token\":\"90a58908a2209ff9dfdfd668f142158a\",\"face_rectangle\":{\"top\":165,\"left\":219,\"width\":122,\"height\":122},\"attributes\":{\"gender\":{\"value\":\"Female\"},\"age\":{\"value\":23},\"smile\":{\"value\":59.325,\"threshold\":50.000},\"emotion\":{\"anger\":0.004,\"disgust\":0.004,\"fear\":0.004,\"happiness\":1.131,\"neutral\":98.729,\"sadness\":0.124,\"surprise\":0.004}}}],\"image_id\":\"Lbu4Vn06T8mcyCfqy8RLYw==\",\"face_num\":1}\\n'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'face_num': 1,\n",
       " 'faces': [{'attributes': {'age': {'value': 23},\n",
       "    'emotion': {'anger': 0.004,\n",
       "     'disgust': 0.004,\n",
       "     'fear': 0.004,\n",
       "     'happiness': 1.131,\n",
       "     'neutral': 98.729,\n",
       "     'sadness': 0.124,\n",
       "     'surprise': 0.004},\n",
       "    'gender': {'value': 'Female'},\n",
       "    'smile': {'threshold': 50.0, 'value': 59.325}},\n",
       "   'face_rectangle': {'height': 122, 'left': 219, 'top': 165, 'width': 122},\n",
       "   'face_token': '90a58908a2209ff9dfdfd668f142158a'}],\n",
       " 'image_id': 'Lbu4Vn06T8mcyCfqy8RLYw==',\n",
       " 'request_id': '1603532271,6e3be2f7-782c-4902-9e36-246fe16ab589',\n",
       " 'time_used': 736}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results = r.json() \n",
    "results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "api_secret ='N7rXgft8DfOfDM_E0_vXkkJfnqo8mmxs'\n",
    "api_key ='1yIL3rfLicVRlj6rVnGfzbnuq3-zD_FU'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'face_added': 0,\n",
       " 'face_count': 0,\n",
       " 'faceset_token': '6d1489570ec26ade02586ec049d18f0a',\n",
       " 'failure_detail': [],\n",
       " 'outer_id': '3601',\n",
       " 'request_id': '1603532545,dc0fe4e6-c3b8-4cfb-a9de-1378098e697a',\n",
       " 'time_used': 159}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests,json\n",
    "\n",
    "display_name = \"ia\" #自定义人脸集合的名字\n",
    "outer_id = \"3601\" #自定义标识\n",
    "user_data = \"face\" #自定义用户信息\n",
    "\n",
    "CreateFace_Url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/create\" #调用URL\n",
    "payload = {\n",
    "    # 请求参数\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'display_name':display_name,\n",
    "    'outer_id':outer_id,\n",
    "    'user_data':user_data\n",
    "}\n",
    "r = requests.post(CreateFace_Url, params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'display_name': 'ia',\n",
       " 'face_count': 0,\n",
       " 'face_tokens': [],\n",
       " 'faceset_token': '6d1489570ec26ade02586ec049d18f0a',\n",
       " 'outer_id': '3601',\n",
       " 'request_id': '1603532583,0db00d00-4f57-417c-ab48-c68d66682cd7',\n",
       " 'tags': '',\n",
       " 'time_used': 128,\n",
       " 'user_data': 'face'}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "GetDetail_Url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/getdetail\"\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'outer_id':outer_id,\n",
    "}\n",
    "r = requests.post(GetDetail_Url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'face_added': 0,\n",
       " 'face_count': 1,\n",
       " 'faceset_token': '6d1489570ec26ade02586ec049d18f0a',\n",
       " 'failure_detail': [],\n",
       " 'outer_id': '3601',\n",
       " 'request_id': '1603532875,e28ab6e0-afa5-4158-8239-95f19755f849',\n",
       " 'time_used': 97}"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace_url = \" https://api-cn.faceplusplus.com/facepp/v3/faceset/addface\"\n",
    "\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'faceset_token':'6d1489570ec26ade02586ec049d18f0a',\n",
    "    'face_tokens':'90a58908a2209ff9dfdfd668f142158a',\n",
    "}\n",
    "r = requests.post(AddFace_url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'face_count': 0,\n",
       " 'face_removed': 1,\n",
       " 'faceset_token': '6d1489570ec26ade02586ec049d18f0a',\n",
       " 'failure_detail': [],\n",
       " 'outer_id': '3601',\n",
       " 'request_id': '1603532917,2fa85be3-8ce9-4b7f-a606-8cb1749ebf24',\n",
       " 'time_used': 163}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "RemoveFace_url = \" https://api-cn.faceplusplus.com/facepp/v3/faceset/removeface\"\n",
    "\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "     'faceset_token':'6d1489570ec26ade02586ec049d18f0a',\n",
    "    'face_tokens':'90a58908a2209ff9dfdfd668f142158a',\n",
    "}\n",
    "r = requests.post(RemoveFace_url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '6d1489570ec26ade02586ec049d18f0a',\n",
       " 'outer_id': '3601',\n",
       " 'request_id': '1603532972,64f1f2bd-fdd5-4cd7-92ef-cf1f46a7e719',\n",
       " 'time_used': 72}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Update_url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/update\"\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'faceset_token':'6d1489570ec26ade02586ec049d18f0a',\n",
    "    'user_data':\"face\",\n",
    "}\n",
    "r = requests.post(Update_url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'confidence': 40.071,\n",
       " 'faces1': [{'face_rectangle': {'height': 158,\n",
       "    'left': 291,\n",
       "    'top': 331,\n",
       "    'width': 158},\n",
       "   'face_token': '2fb907cb2bac5b29a4f3edb2d881ac79'}],\n",
       " 'faces2': [{'face_rectangle': {'height': 204,\n",
       "    'left': 420,\n",
       "    'top': 225,\n",
       "    'width': 204},\n",
       "   'face_token': '795cc98b7b55f60d1b666f5f2811033e'}],\n",
       " 'image_id1': '5+JnAhrUtHrIrzcM3sRWJA==',\n",
       " 'image_id2': 'l8qt1lR3HS7/yPI4S3YfYw==',\n",
       " 'request_id': '1603533161,d8a46244-bb90-49ae-909d-72ec77fcc39b',\n",
       " 'thresholds': {'1e-3': 62.327, '1e-4': 69.101, '1e-5': 73.975},\n",
       " 'time_used': 1311}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wan = \"https://gitee.com/huang_jun_hao/wx923/raw/master/wan.jpg\"\n",
    "meijia = \"https://gitee.com/huang_jun_hao/wx923/raw/master/mei.jpg\"\n",
    "\n",
    "Compare_url = \"https://api-cn.faceplusplus.com/facepp/v3/compare\"\n",
    "payload ={\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'image_url1':wan,\n",
    "    'image_url2':meijia,\n",
    "}\n",
    "r = requests.post(Compare_url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
